package util;

/**
 * defines vector utilities for 2D vectors
 * @author jack
 *
 */
public final class VectorUtil
{
	/**
	 * gets the magnitude of the passed vector
	 * @param v
	 * @return returns the magnitude of the passed vector
	 */
	public static double magnitude(double[] v)
	{
		return Math.sqrt(v[0]*v[0]+v[1]*v[1]);
	}
	/**
	 * creates a new array that is the normalized form of the passed vector
	 * @param v
	 * @return returns a normalized copy of the passed vector
	 */
	public static double[] normalize(double[] v)
	{
		double mag = magnitude(v);
		double[] temp = new double[]{v[0]/mag, v[1]/mag};
		return temp;
	}
}
